package interview.sync.array;/*

 */

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @ClassName ArrayListDemo
 * @Author Final
 * @Project DataStructures
 */
public class ArrayListDemo {

    public static void main(String[] args) {
//        ArrayList arrayList=new ArrayList();//线程不安全

//        List arrayList=new Vector<>(); //线程安全

//        List arrayList=Collections.synchronizedList(new ArrayList<>()); //线程安全
        List arrayList =new  CopyOnWriteArrayList();//线程安全
        for (int i=0;i<30;i++){
            new Thread(()->{
                arrayList.add(UUID.randomUUID().toString().subSequence(0,8));
                System.out.println(arrayList);
            },String.valueOf(i)).start();
        }

    }
}
